package com.sx.article.action;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ModelDriven;
import com.sx.article.biz.impl.AttachmentBiz;
import com.sx.article.entity.AttachmentEntity;
import com.sx.core.CoreAction;
import com.sx.feesunit.exception.SXException;

@SuppressWarnings("serial")
public class AttachmentAction extends CoreAction implements ModelDriven<AttachmentEntity> {
	private AttachmentEntity attachment = new AttachmentEntity();
	private AttachmentBiz attachmentbiz;
	private Log log = LogFactory.getLog(this.getClass());
	private File fileimg;
	private String fileimgFileName;
	/**
	 *上传文件数据信息 
	 **/
	public void findMyUploadImage() throws SXException{
		String str = "[]";
		try {
			str = attachmentbiz.findImageByUserInfoId(attachment);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("获取我的图片数据信息",e);
		}
		outJsonString(str);
	}
	/**
	 * 上传图片
	 **/
	public void addImageInfo()throws SXException{
		try {
			String fshortname = attachment.getFshortname();
			String fuserid = attachment.getFuserid();
			attachment = super.getUpdateFileInfo();
			attachment.setFdisplayname(fileimgFileName);
			attachment.setFshortname(fshortname);
			attachment.setFuserid(fuserid);
			Integer id = attachmentbiz.addAttachment(attachment);
			if(id!=null){
				outJsonString("{success:true}");
			}else{
				outJsonString("{success:false}");
			}
		} catch (Exception e) {
			// TODO: handle exception
			log.error("上传表单数据信息",e);
		}
	}
	/**
	 * @return the fileimg
	 */
	public File getFileimg() {
		return fileimg;
	}

	/**
	 * @param fileimg the fileimg to set
	 */
	public void setFileimg(File fileimg) {
		this.fileimg = fileimg;
	}

	/**
	 * @return the fileimgFileName
	 */
	public String getFileimgFileName() {
		return fileimgFileName;
	}

	/**
	 * @param fileimgFileName the fileimgFileName to set
	 */
	public void setFileimgFileName(String fileimgFileName) {
		this.fileimgFileName = fileimgFileName;
	}

	public AttachmentEntity getModel() {
		return attachment;
	}
	/**
	 * @return the attachmentbiz
	 */
	public AttachmentBiz getAttachmentbiz() {
		return attachmentbiz;
	}
	/**
	 * @param attachmentbiz the attachmentbiz to set
	 */
	public void setAttachmentbiz(AttachmentBiz attachmentbiz) {
		this.attachmentbiz = attachmentbiz;
	}

	
}
